﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Reflection;

namespace WMVConvert.Metadata
{
	public partial class WMAttributeList : IBindingList, ICollection<WMAttribute>
	{
		private Editor editor;

		public WMAttributeList(Editor editor)
		{
			this.editor = editor;
		}

		#region IBindingList Members

		public void AddIndex(PropertyDescriptor property)
		{
			throw new NotImplementedException();
		}

		public object AddNew()
		{
			throw new NotImplementedException();
		}

		public bool AllowEdit
		{
			get { return false; }
		}

		public bool AllowNew
		{
			get { return false; }
		}

		public bool AllowRemove
		{
			get { return false; }
		}

		public void ApplySort(PropertyDescriptor property, ListSortDirection direction)
		{
			throw new NotImplementedException();
		}

		public int Find(PropertyDescriptor property, object key)
		{
			throw new NotImplementedException();
		}

		public bool IsSorted
		{
			get { return false; }
		}

		public event ListChangedEventHandler ListChanged
		{
			add
			{
			}
			remove
			{
			}
		}

		public void RemoveIndex(PropertyDescriptor property)
		{
			throw new NotImplementedException();
		}

		public void RemoveSort()
		{
			throw new NotImplementedException();
		}

		public ListSortDirection SortDirection
		{
			get { return ListSortDirection.Ascending; }
		}

		public PropertyDescriptor SortProperty
		{
			get { throw new NotImplementedException(); }
		}

		public bool SupportsChangeNotification
		{
			get { return false; }
		}

		public bool SupportsSearching
		{
			get { return false; }
		}

		public bool SupportsSorting
		{
			get { return false; }
		}

		#endregion

		#region IList Members

		public int Add(object value)
		{
			throw new NotImplementedException();
		}

		public bool Contains(object value)
		{
			throw new NotImplementedException();
		}

		public int IndexOf(object value)
		{
			throw new NotImplementedException();
		}

		public void Insert(int index, object value)
		{
			throw new NotImplementedException();
		}

		public bool IsFixedSize
		{
			get { throw new NotImplementedException(); }
		}

		public void Remove(object value)
		{
			throw new NotImplementedException();
		}

		public void RemoveAt(int index)
		{
			throw new NotImplementedException();
		}

		private WMAttribute FindByIndex(int index)
		{
			int currentIndex = index;
			foreach (WMAttribute attrib in this)
			{
				if (currentIndex == index)
				{
					return attrib;
				}
			}
			throw new ArgumentOutOfRangeException("index");
		}

		public object this[int index]
		{
			get
			{
				return FindByIndex(index);
			}
			set
			{
				throw new NotImplementedException();
			}
		}

		#endregion

		#region ICollection<WMAttribute> Members

		public void Add(WMAttribute item)
		{
			throw new NotImplementedException();
		}

		public void Clear()
		{
			throw new NotImplementedException();
		}

		public bool Contains(WMAttribute item)
		{
			return item.Value != null;
		}

		public void CopyTo(WMAttribute[] array, int arrayIndex)
		{
			throw new NotImplementedException();
		}

		public int Count
		{
			get
			{
				return this.editor.Count;
			}
		}

		public bool IsReadOnly
		{
			get { return false; }
		}

		public bool Remove(WMAttribute item)
		{
			if (item.Value != null)
			{
				item.Value = null;
				return true;
			}
			return false;
		}

		#endregion

		#region IEnumerable<WMAttribute> Members

		public IEnumerator<WMAttribute> GetEnumerator()
		{
			foreach (PropertyInfo prop in this.GetType().GetProperties())
			{
				if (typeof(WMAttribute).IsAssignableFrom(prop.PropertyType) && prop.Name != "Item")
				{
					WMAttribute wmAttrib = (WMAttribute)prop.GetValue(this, null);
					if (wmAttrib.Value != null)
					{
						yield return wmAttrib;
					}
				}
			}
			yield break;
		}

		#endregion

		#region IEnumerable Members

		IEnumerator IEnumerable.GetEnumerator()
		{
			return ((IEnumerable<WMAttribute>)this).GetEnumerator();
		}

		#endregion

		#region ICollection Members

		public void CopyTo(Array array, int index)
		{
			throw new NotImplementedException();
		}

		public bool IsSynchronized
		{
			get { throw new NotImplementedException(); }
		}

		private readonly object syncRoot = new object();

		public object SyncRoot
		{
			get { return syncRoot; }
		}

		#endregion
	}
}
